import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/30 9:11
 * @description 找出1-n的质数个数，然后全排列，剩下的个数全排列，两者相乘
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        solution.numPrimeArrangements(5);
    }

    public static final int MOD = (int) 1e9 + 7;

    public int numPrimeArrangements(int n) {
        int numPrimes = 0;
        for (int i = 1; i <= n; i++) {
            if (isPrime(i)) {
                numPrimes++;
            }
        }
        return (int) (factorial(numPrimes) * factorial(n - numPrimes) % MOD);
    }

    public boolean isPrime(int n) {
        if (n == 1) {
            return false;
        }
        for (int i = 2; i * i <= n; i++) {
            if (n % i == 0) {
                return false;
            }
        }
        return true;
    }

    public long factorial(int n) {
        long res = 1;
        for (int i = 1; i <= n; i++) {
            res *= i;
            res %= MOD;
        }
        return res;
    }
}
